﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Widgets/Widgets.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="server">

    <div class="tabControl addSymbol">
        <a href="#" onclick="$('.addSymbol form').hide();$('#addSymbol').show()">Add Symbol</a>
        <a href="#" onclick="$('.addSymbol form').hide();$('#editSymbols').show()">Edit Symbols</a>
        <form id="addSymbol" method="post" action="<%=Url.Action("Stocks", "Widgets") %>">
            <span>Symbol:&nbsp;
            <input id="symbol" name="symbol" type="text" /></span>
            <span>Buying Price Per Share:&nbsp;$
            <input id="buyPrice" name="buyPrice" type="text" /></span>
            <span>Volume:&nbsp;
            <input id="volume" name="volume" type="text" /></span>
            <span><input name="submitBut" type="submit" value="Add" /></span>
            <input name="action" type="hidden" value="add" />
        </form>
        <form id="editSymbols" method="post" action="<%=Url.Action("Stocks", "Widgets") %>">
            <%
                StockCollection sc = (StockCollection) ViewData["StocksModel"];
                foreach (KeyValuePair<String, Stock> pair in sc.Stocks)
                {
                    Stock stock = pair.Value;
                    %>
                        <div>
                            <span><b><%=stock.Symbol %></b></span>
                            <span><%=stock.Name %></span>
                            <span>
                                Buying Price: $
                                <input name="buyPrice<%=stock.Symbol %>" type="text" value="<%=stock.BuyingPrice %>" />
                            </span>
                            <span>
                                Volume:
                                <input name="volume<%=stock.Symbol %>" type="text" value="<%=stock.Shares %>" />
                            </span>
                            <span>
                                <input type="button" value="Remove" onclick="$('#editAction').val('remove<%= stock.Symbol %>');$('#editSymbols').submit()" />
                            </span>
                        </div>
                    <%
                }
            %>
            <input id="editAction" name="action" type="hidden" value="save" />
            <input name="submitBut" type="hidden" value="Save" />
            <input name="submitBut" type="submit" value="Save" />
        </form>
    </div>
    <%
        foreach (KeyValuePair<String, Stock> pair in sc.Stocks)
        {
            Stock stock = pair.Value;
            %>
                <hr />
                <div class="stockFull">
                    <h2><a href="<%=Url.Action("Stock", "Widgets") %>?symbol=<%=stock.Symbol %>"><%=stock.Symbol %>
                    <%=stock.Name %></a></h2>
                    <table>
                        <tr>
                            <td>
                                Current Price:
                                <b><%= String.Format("{0:C}", stock.CurrentPrice) %></b>
                            </td>
                            <td>
                                Volume:
                                <b><%=stock.Shares %></b>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Buying Price:
                                <b><%= String.Format("{0:C}", stock.BuyingPrice) %></b>
                            </td>
                            <td>
                                Profit to Date:
                                <b class="<%=(stock.Profit < 0 ? "stockNeg" : "stockPos") %>"><%= String.Format("{0:C}", stock.Profit) %></b>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Profit Today:
                                <b class="<%=(stock.DifferentialProfit < 0 ? "stockNeg" : "stockPos") %>"><%= String.Format("{0:C}", stock.DifferentialProfit) %></b>
                            </td>
                        </tr>
                    </table>
                </div>
            <%
        }
    %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">

</asp:Content>
